<template>
  <el-dialog
    center
    :visible="dialogVisible "
    width="60%"
    title="选择担保人"
    append-to-body
    :before-close="handleClose"
    @closed="handleClose"
    :close-on-click-modal="false"
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
    >
      <el-form-item label="担保人名称">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入担保人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      style="width: 100%;"
      height="500"
    >
      <el-table-column
        prop="customerName"
        label="担保人名称"
      ></el-table-column>
      <el-table-column
        prop="customerType"
        label="担保人类型"
      >
        <template #default="{row}">
          {{ row.customerType === '01' ? '法人' : '自然人' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="customerCreditcode"
        label="证件号码"
      >
        <template #default="{row}">
          {{ row.customerType === '01' ? row.creditCode : row.customerCreditcode }}
        </template>
      </el-table-column>
      <el-table-column
        prop="customerPhone"
        label="联系电话"
      >
        <template #default="{row}">
          {{ row.customerType === '01' ? row.legalpersonPhone : row.customerPhone }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- icon="el-icon-edit" -->
          <el-button
            size="mini"
            type="text"
            @click="handleOption(scope.row)"
          >选择
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { customerAdmitInfo, customerList, customerInfo } from '@/api/processManage/approveForms'
export default {
  props: ['queryData', 'templateName'],
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: '',
        customerType: '',
        creditCode: '',
        customerCreditcode: ''
      },
      total: 0,
      loading: false
    };
  },
  methods: {
    async sync() {
      this.dialogVisible = true;
      this.resetQuery()
    },
    // 列表
    getList() {
      this.loading = true
      customerList({
        ...this.queryParams,
        ...this.queryData
      }).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false
      })
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleOption(row) {
      // customerInfo({ customerId: row.customerId }).then(data => {
      //   this.$emit('ok', data.data);
      //   this.handleClose();
      // })
      customerInfo({
        customerId: row.customerId
      }).then(res => {
        this.$emit('ok', res.data)
        this.handleClose();
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        customerName: '',
        customerType: '',
        creditCode: '',
        customerCreditcode: ''
      };
      this.handleQuery();
    }
  }
};
</script>
<style lang="scss" scoped>
</style>
